package day12;

import java.util.Scanner;

//自定义异常
public class demo9 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入性别：");
        String sex=sc.next();
        if ("男".equals(sex)||"女".equals(sex)){
            System.out.println("您的年龄输入正确！");
        }else { //性别不合理，创建一个自定义性别异常
            try {
                throw new SexException("性别只能输入男或女");
            } catch (SexException e) {
                e.printStackTrace();
            }
        }
    }
}
class SexException extends Exception{
    public SexException(String msg){
        //必须要父类构造，否则msg无法正常赋值
        super(msg);
    }
}